package ar.com.temporis.system.domain;

import java.util.List;

import junit.framework.TestCase;

import ar.com.temporis.system.domain.User;
import ar.com.temporis.util.collection.CollectionFactory;

import com.thoughtworks.xstream.XStream;

/**
 * 
 * @author matias
 *
 */
public class FooToXMLTestCase extends TestCase {

	@SuppressWarnings("unchecked")
	public void test() throws Exception {
		XStream stream = createXStream();
		
		Object obj = createObject();
		String xml = stream.toXML(obj);
		System.out.println(xml);
		
		List<User> list = (List<User>) stream.fromXML(xml);
		
		for (User user : list) {
			System.out.println(user.getNick());
		}
	}

	private XStream createXStream() {
		XStream stream = new XStream();
		
		stream.alias(User.class.getSimpleName(), User.class);
		
		return stream;
	}

	private Object createObject() {
		List<User> list = CollectionFactory.createList();
		
		list.add(createUser("martu", "231234", "martina"));
		list.add(createUser("jaqui", "231234", "jaquelina"));
		
		return list;
	}

	private User createUser(String nick, String password, String username) {
		User user = new User();
		
		user.setNick(nick);
		user.setPassword(password);
		user.setUsername(username);
		
		return user;
	}

}
